using Digitalmes.Domain;

namespace Digitalmes.Infrastructure.Scada.Handlers;

/// <summary>
/// 日志记录帮助对象。
/// </summary>
internal static class LoggerHelper
{
    public static ScadaResult LogAndReturn(ILogger logger, string msgHeader, string lineName, string wsCode, ErrorCode errCode)
    {
        var result = ScadaResult.Error(errCode);
        logger.LogWarning("[{MsgHeader}] 产线：{LineName}，工位：{WsCode}，状态: {State}, 消息: [{InnerErrorCode}]-{ErrMessage}",
            msgHeader,
            lineName,
            wsCode,
            result.State.ToString(),
            result.InnerErrorCode.ToString(),
            result.GetErrorMessage());

        return result;
    }
}
